package model

import "time"

type Model struct {
	Id        uint      `json:"id" gorm:"primarykey,autoIncrement" form:"id"`
	CreatedAt time.Time `json:"createdAt" form:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt" form:"updatedAt"`
}
type PageInfo struct {
	Total    int64 `json:"total,omitempty"`
	PageSize int   `json:"pageSize,omitempty"`
	PageNo   int   `json:"pageNo,omitempty"`
}

type ResponseEntity struct {
	Data     interface{} `json:"data,omitempty"`
	Success  bool        `json:"success"`
	Message  string      `json:"message,omitempty"`
	PageInfo *PageInfo   `json:"pageInfo,omitempty"`
}
type PageQuery struct {
	PageNo   int `json:"-" form:"pageNo"`
	PageSize int `json:"-" form:"pageSize"`
}

var ParamErrorModel = ResponseEntity{
	Message: "参数错误",
}

var SuccessEntityModel = func(data interface{}) ResponseEntity {
	return ResponseEntity{
		Data:    data,
		Success: true,
		Message: "成功",
	}
}

var BoolEntityModel = func(data bool, err error) ResponseEntity {
	var message string
	if err != nil {
		message = err.Error()
	}
	return ResponseEntity{
		Data:    data,
		Success: data,
		Message: message,
	}
}

var PageEntityModel = func(data interface{}, page *PageInfo) ResponseEntity {
	return ResponseEntity{
		Data:     data,
		Success:  true,
		PageInfo: page,
	}
}

var FailEntityModel = func(failMessage string) ResponseEntity {
	return ResponseEntity{
		Success: false,
		Message: failMessage,
	}
}

var UnauthorizedEntityModel = ResponseEntity{
	Success: false,
	Message: "访问未授权",
}
